﻿using System;
using HRMSystemShi.DAL;
using HRMSystemShi.Model;

namespace HRMSystemShi._2025
{
    public partial class FormFixPassword : Form
    {
        public FormFixPassword()
        {
            InitializeComponent();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            LoginUserInfo User = LoginUserInfo.GetInstance();
            string? UserName = User.UserName;
            OperatorService operatorService = new OperatorService();
            Operator? op = operatorService.GetOperator(UserName!);
            if (op != null)
            {
                if (op.Password == CommonHelper.GetMD5(textBoxNewPassword.Text))
                {
                    CommonHelper.MessageError("新密码不能与旧密码相同！");
                }
                else if (textBoxNewPassword.Text != textBoxCheckPassword.Text)
                {
                    CommonHelper.MessageError("两次输入的密码不一致！");
                }
                else
                {
                    OperatorService.UpdatePassword(UserName!, CommonHelper.GetMD5(textBoxNewPassword.Text));
                    CommonHelper.MessageSuccess("密码修改成功！");
                    this.Close();
                }
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            if(CommonHelper.MessageYesOrNo("是否退出？") == DialogResult.Yes)
            {
                this.Close();
            }
        }
    }
}
